﻿using LaunchAllaround.DesignPattern.MVC;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace LaunchAllaround.Sound
{
    /// <summary>
    /// Logique d'interaction pour AudioSettings.xaml
    /// </summary>
    public partial class AudioSettings : UserControl, View<SongPlayer>, Controller<SongPlayer>
    {
        public AudioSettings()
        {
            InitializeComponent();
        }


        public AudioSettings(SongPlayer model)
        {
            InitializeComponent();
            this.SetModel(model);
            this.BPMText.Text = ((SongPlayer)(this.model)).Bpm.ToString();
            this.MeasureText.Text = ((SongPlayer)(this.model)).Measure.ToString();
            if (((SongPlayer)(this.model)).MuteBpm == true) { this.BPMActivationText.Text = "OFF"; }
            else { this.BPMActivationText.Text = "ON"; }
        }

        public void Refresh(RefreshEvent<SongPlayer> ev)
        {
            if (ev is RefreshBpm)
            {
                int bpm = ((RefreshBpm)ev).Bpm;
                this.BPMText.Text = bpm.ToString();
            }
            else if (ev is RefreshMeasure)
            {
                int measure = ((RefreshMeasure)ev).Measure;
                this.MeasureText.Text = measure.ToString();
            }
            else if (ev is RefreshMuteBpm)
            {
                bool mutebpm = ((RefreshMuteBpm)ev).MuteBpm;
                if (mutebpm == true) { this.BPMActivationText.Text = "OFF"; }
                else { this.BPMActivationText.Text = "ON"; }
            }
        }

        private Model<SongPlayer> model;

        public void SetModel(Model<SongPlayer> model)
        {
            this.model = model;
        }
        public Model<SongPlayer> GetModel()
        {
            return this.model;
        }

        private void BeginHighlight(object sender, MouseEventArgs e)
        {
            ((Image)sender).Opacity = 1;
        }

        private void StopHighlight(object sender, MouseEventArgs e)
        {
            ((Image)sender).Opacity = 0.5;
        }

        private void IncreaseBPM(object sender, MouseButtonEventArgs e)
        {
            ((SongPlayer)(this.model)).Bpm = ((SongPlayer)(this.model)).Bpm + 1;
        }

        private void DecreaseBpm(object sender, MouseButtonEventArgs e)
        {
            ((SongPlayer)(this.model)).Bpm = ((SongPlayer)(this.model)).Bpm - 1;
        }

        private void SetBPM(object sender, MouseButtonEventArgs e)
        {
            ((SongPlayer)(this.model)).MuteBpm = !((SongPlayer)(this.model)).MuteBpm;
        }

        private void IncreaseMeasure(object sender, MouseButtonEventArgs e)
        {
            ((SongPlayer)(this.model)).Measure = ((SongPlayer)(this.model)).Measure + 1;
        }

        private void DecreaseMeasure(object sender, MouseButtonEventArgs e)
        {
            ((SongPlayer)(this.model)).Measure = ((SongPlayer)(this.model)).Measure - 1;
        }

        private void StopPreviewEvent(object sender, MouseButtonEventArgs e)
        {
            SongPlayer sp = SongPlayer.myself;
            sp.Stop();
        }

    }
}
